import 'package:dsp_bt_audio/modules/model.dart';
import 'package:dsp_bt_audio/tool/assets.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';
import 'package:flutter_kit_plus/flutter_kit.dart';

class SliderItem extends StatefulWidget {
  Model model;
  void Function(double value, bool isSend) onChange;
  void Function(bool isLeft) onStepChange;

  SliderItem({super.key, required this.model, required this.onChange, required this.onStepChange});

  @override
  State<SliderItem> createState() => _SliderItemState();
}

class _SliderItemState extends State<SliderItem> {
  Widget imgBtn(bool isleft) {
    return myIconButton(
      width: 30,
      height: 30,
      iconName: isleft ? assets.arrow_left : assets.arrow_right,
      onTap: () => widget.onStepChange(isleft),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: Container(
        padding: EdgeInsets.only(left: 10, right: 10),
        child: Row(
          spacing: 2,
          children: [
            Container(
              width: 90,
              color: Colors.transparent,
              child: FittedBox(
                fit: BoxFit.scaleDown,
                alignment: Alignment.centerLeft,
                child: Text(widget.model.title, maxLines: 1),
              ),
            ),
            Flexible(
              flex: 3,
              child: Row(
                spacing: 5,
                children: [
                  imgBtn(true),
                  Expanded(
                    child: Obx(() {
                      return kSlider(
                        sliderThemeData: SliderThemeData(
                          thumbShape: SliderTextThumbShape(
                            text: widget.model.isint ? '${widget.model.value.toInt()}' : '${widget.model.value}',
                            textStyle: TextStyle(fontSize: 8, color: Colors.black),
                            thumbRadius: 12,
                            thumbColor: Color_theme,
                            numberColor: Colors.black,
                            drawTextRotate: 0,
                          ),
                          overlayShape: const RoundSliderOverlayShape(overlayRadius: 0.0), // 设置圆点到两端的间距为 0 以减小间距
                          trackHeight: 4,
                          activeTrackColor: Color_theme,
                          inactiveTrackColor: Color_inTrackColor,
                          tickMarkShape: RoundSliderTickMarkShape(tickMarkRadius: 0), //不显示刻度
                        ),
                        dirction: Axis.vertical,
                        value: widget.model.value.value,
                        min: widget.model.min,
                        max: widget.model.max,
                        step: widget.model.step,
                        label: widget.model.isint
                            ? widget.model.value.value.toInt().toString()
                            : widget.model.value.value.toString(),
                        onChanged: (currentValue) => widget.onChange(currentValue, false),
                        onChangedForSend: (currentValue) => widget.onChange(currentValue, true),
                      );
                    }),
                  ),
                  imgBtn(false),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
